<?php

namespace backend\modules\orders\models;

use Yii;

/**
 * This is the model class for table "invoice".
 *
 * @property string $invoice_id
 * @property string $order_id
 * @property integer $invoice_type
 * @property integer $is_payed
 * @property integer $porc
 * @property string $p_tel
 * @property string $c_name
 * @property string $c_code
 * @property string $p_email
 * @property string $order_sn
 * @property string $hav_buil
 *
 * @property OrderInfo $order
 */
class Invoice extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'invoice';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['invoice_id', 'order_id'], 'required'],
            [['invoice_type', 'is_payed', 'porc','hav_buil'], 'integer'],
            [['invoice_id', 'order_id'], 'string', 'max' => 40],
            [['p_tel', 'order_sn'], 'string', 'max' => 20],
            [['c_name'], 'string', 'max' => 200],
            [['c_code'], 'string', 'max' => 25],
            [['p_email'], 'string', 'max' => 60],
            [['order_id'], 'exist', 'skipOnError' => true, 'targetClass' => OrderInfo::className(), 'targetAttribute' => ['order_id' => 'order_id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'invoice_id' => Yii::t('app', 'Invoice ID'),
            'order_id' => Yii::t('app', 'Order ID'),
            'invoice_type' => Yii::t('app', '发票类型（0：普通发票）'),
            'is_payed' => Yii::t('app', '是否付款'),
            'porc' => Yii::t('app', '公司还是个人(0个人1公司)'),
            'p_tel' => Yii::t('app', '个人电话'),
            'c_name' => Yii::t('app', '公司名称'),
            'c_code' => Yii::t('app', '公司税号'),
            'p_email' => Yii::t('app', '个人邮箱'),
            'order_sn' => Yii::t('app', '订单号'),
            'hav_buil' => Yii::t('app', '是否已处理'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getOrder()
    {
        return $this->hasOne(OrderInfo::className(), ['order_id' => 'order_id']);
    }

    /**
     * @inheritdoc
     * @return \backend\modules\orders\models\query\InvoiceQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new \backend\modules\orders\models\query\InvoiceQuery(get_called_class());
    }
}
